import { Body, Controller, Get, Post, Req, Param } from '@nestjs/common';
import { OrderService } from './order.service';
import { OrderDto, QueryOrderPage } from '@/dto/order.dto';
import { IsObjectIdPipe } from '@/pipe';

@Controller('order')
export class OrderController {
  constructor(private readonly orderService: OrderService) {}

  @Post('create')
  createOrder(@Req() req: any, @Body() order: OrderDto) {
    return this.orderService.createOrder(req.user.id, order);
  }

  @Get('query/:id')
  queryOrder(@Param('id', IsObjectIdPipe) id: string) {
    return this.orderService.findOrderById(id);
  }

  @Post('queryList')
  queryOrderList(@Req() req: any, @Body() orderPage?: QueryOrderPage) {
    return this.orderService.findOrdersByCreatorId(req.user.id, orderPage);
  }
}
